public class Complex {

	private double realPart;
	private double unrealPart;

	public Complex(double real, double unreal) {
		this.realPart = real;
		this.unrealPart = unreal;
	}

	public Complex() {
		this.realPart = 0;
		this.unrealPart = 0;
	}

	public Complex add(Complex complex) {
		return new Complex(this.realPart + complex.realPart, this.unrealPart + complex.unrealPart);
	}

	public Complex minus(Complex complex) {
		return new Complex(this.realPart - complex.realPart, this.unrealPart - complex.unrealPart);
	}

	public Complex multi(Complex complex) {
		double real = this.realPart * complex.realPart - this.unrealPart * complex.unrealPart;
		double unreal = this.realPart * complex.unrealPart + this.unrealPart * complex.realPart;
		return new Complex(real,unreal);
	}

	public Complex devide(Complex complex) {
		Complex adjoint = new Complex(complex.realPart, -complex.unrealPart);
		double denominator = complex.multi(adjoint).realPart;
		if(denominator != 0){
			Complex numerator = this.multi(adjoint);
			return new Complex(numerator.realPart/denominator, numerator.unrealPart/denominator);
		}
		
		return null;
	}
	
	public boolean isEqual(Complex complex){
		return this.realPart == complex.realPart && this.unrealPart == complex.unrealPart;
	}
	
	public String toString(){
		if(this.realPart != 0 && this.unrealPart != 0)
			return this.realPart + " + " + this.unrealPart + "*i";
	
		if(this.realPart == 0)
			return this.unrealPart + "*i";
					
		return this.realPart+"";
	}

}
